/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mvp.levelup.hashs.map;

import java.util.AbstractMap;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

/**
 *
 * @author WORKSPOT2
 */
public class HashMapTest
{

    public static void main(String args[])
    {
        HashMap<Integer, String> map = new HashMap<Integer, String>();
        map.put(4, "Four");
        map.put(6, "Six");
        map.put(4, "Four222");
        map.put(10, "Ten");
        map.put(11, "Eleven");
        map.put(56, "Fifty six");
        map.put(90, "ddd");
        map.put(1598, "hhhhssdd");
        map.put(46634, "bbsdddd");
        showMap(map);
        Entry<String, String> myEntry = new AbstractMap.SimpleEntry<String, String>("ddd", "lll");
        
        String res = map.get(10);
        System.out.println(res);
        boolean cont1 = map.containsKey(11);
        boolean cont2 = map.containsKey(12);
        System.out.println("Cont1: " + cont1);
        System.out.println("Cont2: " + cont2);
        int sizeBefore = map.size();
        System.out.println("Before: " + sizeBefore);
        map.remove(56);
        int sizeAfter = map.size();
        System.out.println("After: " + sizeAfter);
        Iterator<Integer> keys = map.keySet().iterator();
        while (keys.hasNext())
        {
            System.out.println(keys.next());
        }
        Iterator<String> values = map.values().iterator();
        while (values.hasNext())
        {
            System.out.println(values.next());
        }

    }

    private static void showMap(Map<Integer, String> map)
    {
        Iterator<Entry<Integer, String>> iter = map.entrySet().iterator();
        Entry<Integer, String> tmp;
        while (iter.hasNext())
        {
            tmp = iter.next();
            System.out.println(tmp.getKey() + " - " + tmp.getValue());
        }
    }
}
